package com.yh.csx.crm.webapi.controller;

import com.yh.csx.crm.appapi.controller.BaseController;
import com.yh.csx.crm.core.entity.CommonResponse;
import com.yh.csx.crm.core.exception.BusinessException;
import com.yh.csx.crm.service.InitializeDataService;
import com.yh.csx.crm.service.vo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

/**
 * TestController class
 *
 * @author huyalin
 * @date 2019/3/21
 */
@Slf4j
@Api("数据初始化")
@RestController
@RequestMapping("/initialize")
public class InitializeDataController extends BaseController {

    @Autowired
    InitializeDataService initializeDataService;

    @ApiOperation("导入审批节点人员")
    @PostMapping("/input_node_person")
    public CommonResponse inputNodePerson(MultipartFile file) {
        return super.visit(() -> {
            User user = new User(super.getUserId(), super.getUserName());
            if (Objects.isNull(file) || file.isEmpty()) {
                throw new BusinessException("文件为空");
            }
            initializeDataService.inputNodePerson(user, file);
        });
    }
}
